﻿Public Class VACCINEICD
    Dim connect As CONDB = CONDB.NewConnection
    Dim s As FILTERCLASS
    Private Sub VACCINEICD_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridVaccineicd()
        SearchICD()
        SearchVACCINE()
    End Sub
    Private Sub SelectDatagridVaccineicd()
        Dim objSelectDataVaccineicd As New VACCINEICDCLASS
        Dim Vaccineicd As DataTable
        Vaccineicd = connect.GetTable(objSelectDataVaccineicd.SelectMasvaccineicd_)
        MASVACCINEICDGrid.PrimaryGrid.DataSource = Vaccineicd
    End Sub
    Private Sub SearchICD()
        Dim sql2 As String
        sql2 = "SELECT CAST(icdid AS CHAR(4)) AS icdid,icdcode,icddesc_th FROM masdiagcode WHERE STATUS = '1' "
        s = New FILTERCLASS(ICDIDTxt, sql2, "รหัส,รหัส ICD,ชื่อรหัสโรคภาษาไทย", "50,80,113", "0,1,1", "1,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 1 'settext
        s.SetShowBorder = True
    End Sub
    Private Sub SearchVACCINE()
        Dim sql2 As String
        sql2 = "SELECT CAST(vaccineid AS CHAR(4)) AS vaccineid,vaccode,vaccine_th FROM masvaccine WHERE STATUS = '1' "
        s = New FILTERCLASS(VACCINEIDTxt, sql2, "รหัส,รหัสวัคซีน,ชื่อวัคซีนภาษาไทย", "50,80,113", "0,1,1", "1,1,1")
        s.SetTagIndex = 0 ' settag
        s.SetTextIndex = 1 'settext
        s.SetShowBorder = True
    End Sub
    Private Sub addMasVaccineicd_Click(sender As Object, e As EventArgs) Handles addMasVaccineicd.Click
        If ICDIDTxt.Text.Length > 0 Then
            Dim objinsertdata As New VACCINEICDCLASS
            If Convert.ToString(ICDIDTxt.Tag).Trim <> "" Then
                objinsertdata.ICDID_ = Convert.ToString(ICDIDTxt.Tag).Trim
            End If
            If Convert.ToString(VACCINEIDTxt.Tag).Trim <> "" Then
                objinsertdata.VACCINEID_ = Convert.ToString(VACCINEIDTxt.Tag).Trim
            End If
            objinsertdata.STATUS_ = MasVACCINEICDstatuscheck.Checked
            objinsertdata.insertVaccineicdData()

            SelectDatagridVaccineicd()

            cleardata()
        End If
    End Sub
    Private Sub editMasVaccineicd_Click(sender As Object, e As EventArgs) Handles editMasVaccineicd.Click
        If VICDIDTxt.Text.Length > 0 Then
            Dim editStat As Integer
            editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลส่วนดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)
            If editStat = 1 Then
                Dim objeditData As New VACCINEICDCLASS
                If Convert.ToString(ICDIDTxt.Tag) <> "" Then
                    objeditData.ICDID_ = Convert.ToString(ICDIDTxt.Tag)
                End If
                If Convert.ToString(VACCINEIDTxt.Tag) <> "" Then
                    objeditData.VACCINEID_ = Convert.ToString(VACCINEIDTxt.Tag)
                End If
                objeditData.STATUS_ = MasVACCINEICDstatuscheck.Checked
                objeditData.editVaccineicddata()

                SelectDatagridVaccineicd()

                cleardata()

            End If
        Else
            MsgBox("โปรดระบุข้อมูลให้ครบถ้วน", MsgBoxStyle.Critical)
        End If
        addMasVaccineicd.Enabled = True
    End Sub
    Private Sub cleardata()
        ICDIDTxt.Text = ""
        VACCINEIDTxt.Text = ""
        VICDIDTxt.Text = ""
    End Sub

    Private Sub MASVACCINEICDGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASVACCINEICDGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'MsgBox(CType(e.GridPanel.Rows(e.GridCell.RowIndex), DevComponents.DotNetBar.SuperGrid.GridRow).Cells("billid").Value())
        If grid.Cells("vicdid").Value() IsNot DBNull.Value Then
            VICDIDTxt.Text = CType(e.GridPanel.Rows(e.GridCell.RowIndex), DevComponents.DotNetBar.SuperGrid.GridRow).Cells("vicdid").Value()
        Else
            VICDIDTxt.Text = ""
        End If
        If grid.Cells("vaccineid").Value() IsNot DBNull.Value Then
            VACCINEIDTxt.Tag = CType(e.GridPanel.Rows(e.GridCell.RowIndex), DevComponents.DotNetBar.SuperGrid.GridRow).Cells("vaccineid").Value()
        Else
            VACCINEIDTxt.Tag = ""
        End If
        If grid.Cells("วัคซีน").Value() IsNot DBNull.Value Then
            VACCINEIDTxt.Text = CType(e.GridPanel.Rows(e.GridCell.RowIndex), DevComponents.DotNetBar.SuperGrid.GridRow).Cells("วัคซีน").Value()
        Else
            VACCINEIDTxt.Text = ""
        End If
        If grid.Cells("icdid").Value() IsNot DBNull.Value Then
            ICDIDTxt.Tag = CType(e.GridPanel.Rows(e.GridCell.RowIndex), DevComponents.DotNetBar.SuperGrid.GridRow).Cells("icdid").Value()
        Else
            ICDIDTxt.Tag = ""
        End If
        If grid.Cells("ชื่อรหัสโรคภาษาไทย").Value() IsNot DBNull.Value Then
            ICDIDTxt.Text = CType(e.GridPanel.Rows(e.GridCell.RowIndex), DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อรหัสโรคภาษาไทย").Value()
        Else
            ICDIDTxt.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            MasVACCINEICDstatuscheck.Checked = True
        Else
            MasVACCINEICDstatuscheck.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE masvaccineicd SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`STATUS` = 1 "
                Else
                    Sql += "`STATUS` = 0 "
                End If
                Sql += "WHERE `vicdid` = '" & VICDIDTxt.Text & "' ;"
                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub

End Class